/**
 * 
 */
package com.maohi.software.tupuna.home.bundle.ui;

import java.awt.BorderLayout;
import java.awt.Component;

import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;

import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.maohi.software.tupuna.constants.UIConstant;
import com.maohi.software.tupuna.interfaces.BundleApi;

/**
 * @author heifara
 * 
 */
public class BundleUI extends JPanel implements BundleApi, Runnable {

	private static final long serialVersionUID = 1L;

	@Inject
	@Named(UIConstant.BUNDLE_MENU_UI)
	private Component menuUi;

	@Inject
	@Named(UIConstant.BUNDLE_TOOLBAR_UI)
	private Component toolbarUi;

	@Inject
	@Named(UIConstant.BUNDLE_CONTENT_UI)
	private JTabbedPane contentUi;

	@Inject
	protected void initUI() {
		this.contentUi = new JTabbedPane();
		this.contentUi.addTab("Welcome note", new JPanel());
	}

	@Override
	public void run() {
		this.update();
	}

	@Override
	public void setMenuEnable(boolean aEnable) {
		this.menuUi.setVisible(aEnable);
		SwingUtilities.invokeLater(this);
	}

	@Override
	public void setToolbarEnable(boolean aEnable) {
		this.toolbarUi.setVisible(aEnable);
		SwingUtilities.invokeLater(this);
	}

	protected void update() {
		this.removeAll();

		this.setLayout(new BorderLayout(0, 10));

		JPanel iPanel = new JPanel(new BorderLayout());
		iPanel.add(this.toolbarUi, BorderLayout.NORTH);
		iPanel.add(this.contentUi, BorderLayout.CENTER);

		JSplitPane iSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.menuUi, iPanel);
		this.add(iSplitPane, BorderLayout.CENTER);
	}

}
